//
//  CatalogCell.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/8/8.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "CatalogCell.h"

@implementation CatalogCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _animView = [[UIView alloc] init];
        [self.contentView addSubview:_animView];
        [_animView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(30);
            make.top.equalTo(self.contentView.mas_top).offset(10);
            make.height.mas_equalTo(40);
            make.width.mas_equalTo(50);
        }];
        [self musicReplicatorLayer:_animView];
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_animView.mas_right).offset(scaleLeftAndRight(0));
            make.right.equalTo(self.contentView.mas_right);
            make.top.equalTo(self.contentView.mas_top).offset(scaleTopAndBottom(10));
            make.height.mas_equalTo(scaleTopAndBottom(40));
        }];
        self.selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, WIDTH, scaleTopAndBottom(60))];
        [self.selectBtn addTarget:self action:@selector(selectPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.selectBtn];
    }
    return self;
}
- (void)musicReplicatorLayer:(UIView *)fatherView
{
    _musicLayer = [CAReplicatorLayer layer];
    _musicLayer.frame = CGRectMake(0, 0, 50, 30);
    //设置复制层里面包含的子层个数
    _musicLayer.instanceCount = 4;
    //设置下个子层相对于前一个的偏移量
    _musicLayer.instanceTransform = CATransform3DMakeTranslation(10, 0, 0);     //每个layer的间距。
    //设置下一个层相对于前一个的延迟时间
    _musicLayer.instanceDelay = 0.2;
//    _musicLayer.backgroundColor = [UIColor cyanColor].CGColor;
    _musicLayer.masksToBounds = YES;
    [fatherView.layer addSublayer:_musicLayer];
    CALayer *tLayer = [CALayer layer];
    tLayer.frame = CGRectMake(10, 20, 3, 20);
    tLayer.backgroundColor = [UIColor orangeColor].CGColor;
    [_musicLayer addSublayer:tLayer];
    CABasicAnimation *musicAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
    musicAnimation.duration = 0.35;
    musicAnimation.fromValue = @(tLayer.frame.size.height);
    //    musicAnimation.toValue = @(tLayer.frame.size.height - 10);
    musicAnimation.byValue = @(20);
    musicAnimation.autoreverses = YES;
    musicAnimation.repeatCount = MAXFLOAT;
    [tLayer addAnimation:musicAnimation forKey:@"musicAnimation"];
}
- (void)selectPressed:(UIButton *)sender{
    self.isSelect = !self.isSelect;
    if (self.qhxSelectBlock) {
        self.qhxSelectBlock(self.isSelect,sender.tag);
    }
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
